package com.api.oa.mapper;

import com.api.oa.model.entity.YQDistrict;
import com.api.oa.model.vo.OaNoticeVo;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface YQDistrictMapper {

    @Insert("insert into  yq_district  (" +
        "districtName," +
        "districtPid," +
        "districtLevel," +
        "districtRouter" +
        ") " +
        "values " +
        "(" +
        "#{entity.districtName}," +
        "#{entity.districtPid}," +
        "#{entity.districtLevel}," +
        "#{entity.districtRouter}" +
    ")" )
    @Options(useGeneratedKeys = true, keyProperty = "districtId", keyColumn = "id")
    Integer insert(@Param("entity") YQDistrict entity);



    @Update("update  yq_district  set " +
        "districtName = #{entity.districtName}," +
        "districtPid = #{entity.districtPid}," +
        "districtLevel = #{entity.districtLevel}" +
    " where districtId = #{entity.districtId}")
    Integer update(@Param("entity") YQDistrict  entity);


    @Delete("delete from yq_district where districtId=#{id}")
    void delete(@Param("id") Integer id);


    @Select("<script>select * from  yq_district  where <if test='pid==null'>districtPid is null </if>  <if test='pid!=null'> districtPid = #{pid} </if> </script>")
    List<YQDistrict> list(@Param("pid") Integer pid);


    @Select("select * from  yq_district  where districtId = #{id} limit 1")
    YQDistrict findOne(@Param("id") Integer id);

}

